package com.vxdata

import scala.collection.mutable.ListBuffer

object List_demo {
  def main(args: Array[String]): Unit = {
    // TODO List
    // 创建list
    var list = List(1, 2, 3)
    println("添加元素: " + (list ::: List(4, 5)))
    println("删除元素: " + list.diff(List(4, 5)))

    val list1 = List()
    println(list1 ::: List(1, 2))


    val list2 = 1 :: 2 :: 3 :: 4 :: 5 :: Nil
    println(list2)


    // TODO ListBuffer
    // 创建list
    val stringList = new ListBuffer[String]()
    stringList += "1"
    stringList += "2"
    println(stringList)
    stringList.foreach(println)


    /**
     * 对象list
     */
    println("对象list++++++++++++++++++++++++++++++++++++++++")
    val colList = new ListBuffer[Col]()
    colList += Col(1l, "a", "String")
    colList += Col(2l, "b", "Integaer")
    colList += Col(3l, "c", "Long")
    colList += Col(4l, "d", "Booler")

    // 从对象list中获取某个字段的list
    val colNameList: ListBuffer[String] = colList.map(_.colName)
    // 按照条件过滤list`
    colList.filter(_.nodeId > 1).foreach(println)
    // 从对象list中获取两个字段map
    val map: Map[String, String] = colList.map(c => (c.colName, c.colType)).toMap


    println(map)
  }

}

case class Col(
                nodeId: Long = 0,
                colName: String = null,
                colType: String = null
              )
